package com.iwhalecloud.bss.kite.cucc.service.util;

import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.dataservice.cache.DcPublicCache;
import com.iwhalecloud.bss.kite.dataservice.entity.DcPublic;

import java.util.*;

/**
 * @Description 分类ID，产品ID配置获取
 * @Author deng.gang
 * @Date 2021/8/16 11:21 上午
 */
public class ProdCateUtil {

    public static final String MV_CODE = "MV";
    public static final String SDH_CODE = "SDH";
    public static final String YTW_CODE = "YTW";
    public static final String GXCZ_CODE = "GX";
    public static final String DIA_CODE = "DIA";
    public static final String ZQJPW_CODE = "ZQJPW";


    /** 定制NB */
    public static final String DZNB_PROD = "DZNB_PROD";
    /** 定制5G */
    public static final String DZ5G_PROD = "DZ5G_PROD";
    /** 定制3/4G */
    public static final String DZ4G_PROD = "DZ4G_PROD";
    /** 通用5G */
    public static final String TY5G_PROD = "TY5G_PROD";
    /** 通用CAT1 */
    public static final String TYCAT1_PROD = "TYCAT1_PROD";
    /** 通用NB */
    public static final String TYNB_PROD = "TYNB_PROD";
    /** 通用4G */
    public static final String TY4G_PROD = "TY4G_PROD";
    /** 行业5G */
    public static final String HY5G_PROD = "HY5G_PROD";
    /** 工业设备管理平台 */
    public static final String GYSB_PROD = "GYSB_PROD";
    /** 公共事业设备管理平台 */
    public static final String GGSY_PROD = "GGSY_PROD";
    /** 消费电子设备管理平台 */
    public static final String XFDZ_PROD = "XFDZ_PROD";
    /** 设备管理平台体验包 */
    public static final String TYB_PROD = "TYB_PROD";

    /** 应急广播 */
    public static final String GIFT_YJGB_PROD = "GIFT_YJGB_PROD";
    /** 物联网4G健康监测腕表 */
    public static final String GIFT_ZNWB_PROD = "GIFT_ZNWB_PROD";
    /** 物联网智能电表 */
    public static final String GIFT_ZNDB_PROD = "GIFT_ZNDB_PROD";
    /** 物联网智能水表 */
    public static final String GIFT_ZNSB_PROD = "GIFT_ZNSB_PROD";
    /** 物联网智能门磁 */
    public static final String GIFT_ZNMC_PROD = "GIFT_ZNMC_PROD";
    /** 物联网雁飞CAT1模组 */
    public static final String GIFT_YFCAT1_PROD = "GIFT_YFCAT1_PROD";
    /** 物联网金融税控 */
    public static final String GIFT_JRSK_PROD = "GIFT_JRSK_PROD";
    /** 物联网行车记录服务 */
    public static final String GIFT_XCJL_PROD = "GIFT_XCJL_PROD";
    /** 物联网雁飞公网数字对讲 */
    public static final String GIFT_SZDJ_PROD = "GIFT_SZDJ_PROD";
    /** 物联网金融备网 */
    public static final String GIFT_JRBW_PROD = "GIFT_JRBW_PROD";
    /** 物联网雁飞5GCPE */
    public static final String GIFT_YFCPE_PROD = "GIFT_YFCPE_PROD";
    /** 雁飞流动人口房屋管理产品 */
     public static final String GIFT_YFLD_PROD = "GIFT_YFLD_PROD";
    /** 融合子成员定制4G产品 */
    public static final String GIFT_DZ4G_PROD = "GIFT_DZ4G_PROD";
    /** 融合子成员定制连接4G服务包-Cat.1产品 */
    public static final String GIFT_DZCAT1_PROD = "GIFT_DZCAT1_PROD";
    /** 融合子成员CAT1通用连接产品 */
    public static final String GIFT_TYCAT1_PROD = "GIFT_TYCAT1_PROD";
    /** 融合子成员定制5G连接产品（全国）产品 */
    public static final String GIFT_DZ5G_PROD = "GIFT_DZ5G_PROD";
    /** 融合子成员NB通用连接-30MB-36月产品ID */
    public static final String GIFT_TYNB_PROD = "GIFT_TYNB_PROD";
    /** 雁飞智慧燃气 */
    public static final String GIFT_YFZH_PROD = "GIFT_YFZH_PROD";
    /** 雁飞5G智连专线 */
    public static final String GIFT_ZLZX_PROD = "GIFT_ZLZX_PROD";
    /** 雁飞5G智连专线连接产品 */
    public static final String GIFT_ZLZXCAT_PROD = "GIFT_ZLZXCAT_PROD";
    /** 雁飞cat1车辆定位套件 */
    public  static final String GIFT_YFCLDW_PROD = "GIFT_YFCLDW_PROD";
    /** 雁飞CAT1大棚温湿度监控 */
    public static final String GIFT_YFDPJK_PROD = "GIFT_YFDPJK_PROD";
    /** 雁飞4G应急广播大喇叭 */
    public static final String GIFT_YFYJGBT_PROD = "GIFT_YFYJGBT_PROD";
    /** 雁飞5G模组 */
    public  static final String GIFT_YF5G_PROD = "GIFT_YF5G_PROD";
    /** 人员通行智能管理应用平台 */
    public  static final String GIFT_RYTXZN_PROD = "GIFT_RYTXZN_PROD";
    /** 雁飞印章管理套件 */
    public  static final String GIFT_YFYZGL_PROD = "GIFT_YFYZGL_PROD";
    /** NB物联网水务抄表服务-超声波水表 */
    public  static final String GIFT_NBSWCB_PROD = "GIFT_NBSWCB_PROD";



    private static final String STYPE_CATE = "2108161001";
    private static final String STYPE_PROD = "2108161002";
    private static final String STYPE_WLW_PROD = "2108231001";
    private static final String STYPE_OFFER = "20210719001";

    /**
     * 获取五大双线分类ID
     * @return List<String>
     */
    public static List<String> getDoubleLineCateId() {
        List<String> cateIds = new ArrayList<>();
        List<DcPublic> dcPublicList = DcPublicCache.getByPcode(STYPE_CATE, "WDSX_CATE_ID");
        if (Objects.nonNull(dcPublicList)) {
            dcPublicList.forEach(dcPublic -> {
                Optional.ofNullable(dcPublic.getCodea()).ifPresent(cateIds::add);
            });
        }
        return cateIds;
    }
    /**
     * 获取五大双线规格编码offerId
     * @return List<String>
     */
    public static List<String> getDoubleLineOfferId() {
        List<String> offerIds = new ArrayList<>();
        List<DcPublic> dcPublicList = DcPublicCache.get(STYPE_OFFER);
        if (Objects.nonNull(dcPublicList)) {
            dcPublicList.stream().filter(dcPublic -> "1".equals(dcPublic.getCodec())).forEach(dcPublic -> Optional.ofNullable(dcPublic.getPkey()).ifPresent(offerIds::add));
        }
        return offerIds;
    }
    /**
     * 获取政务云分类ID
     * @return List<String>
     */
    public static List<String> getZwyCateId() {
        List<String> cateIds = new ArrayList<>();
        List<DcPublic> dcPublicList = DcPublicCache.getByPcode(STYPE_CATE, "ZWY_CATE_ID");
        if (Objects.nonNull(dcPublicList)) {
            dcPublicList.forEach(dcPublic -> {
                Optional.ofNullable(dcPublic.getCodea()).ifPresent(cateIds::add);
            });
        }
        return cateIds;
    }


    /**
     * 获取五大双线分类ID
     * @return String[]
     */
    public static String[] getDoubleLineCateIdForArr() {
        List<String> cateIds = getDoubleLineCateId();
        return cateIds.toArray(new String[cateIds.size()]);
    }
    /**
     * 获取五大双线OB分类ID
     * @return String[]
     */
    public static String[] getDoubleLineOBCateIdForArr() {
        List<String> cateIds = new ArrayList<>();
        List<DcPublic> dcPublicList = DcPublicCache.getByPcode(STYPE_CATE, "WDSXOB_CATE_ID");
        if (Objects.nonNull(dcPublicList)) {
            dcPublicList.forEach(dcPublic -> {
                Optional.ofNullable(dcPublic.getCodea()).ifPresent(cateIds::add);
            });
        }
        return cateIds.toArray(new String[cateIds.size()]);
    }
    /**
     * 获取IDC商品分类
     * @return String[]
     */
    public static String[] getIDCCateIdForArr() {
        List<String> cateIds = new ArrayList<>();
        List<DcPublic> dcPublicList = DcPublicCache.getByPcode(STYPE_CATE, "IDC_CATE_ID");
        if (Objects.nonNull(dcPublicList)) {
            dcPublicList.forEach(dcPublic -> {
                Optional.ofNullable(dcPublic.getCodea()).ifPresent(cateIds::add);
            });
        }
        return cateIds.toArray(new String[0]);
    }

    /**
     * 根据code：MV, GX, SDH, YTW, DIA 获取分类ID
     * @param code
     * @return
     */
    public static List<String> getCateIdByCode(String... code) {
        List<String> cateIds = new ArrayList<>();
        List<String> codes = Arrays.asList(code);
        if (KiteListUtils.isNotEmpty(codes)) {
            codes.forEach(c -> {
                List<DcPublic> dcPublicList = DcPublicCache.getByPkey(STYPE_CATE, c);
                if (Objects.nonNull(dcPublicList)) {
                    dcPublicList.forEach(dcPublic -> {
                        Optional.ofNullable(dcPublic.getCodea()).ifPresent(cateIds::add);
                    });
                }
            });
        }
        return cateIds;
    }

    /**
     * 根据code：MV, GX, SDH, YTW, DIA 获取分类ID
     * @param code
     * @return
     */
    public static String[] getCateIdByCodeForArr(String... code) {
        List<String> cateIds = getCateIdByCode(code);
        return cateIds.toArray(new String[cateIds.size()]);
    }

    /**
     * 根据code：MV, GX, DIA 获取分类ID
     * @param code
     * @return
     */
    public static String getSingleCateId(String code) {
        return DcPublicCache.getCodea(STYPE_CATE, code);
    }

    /**
     * 根据code：MV, GX, SDH, YTW, DIA 获取产品ID
     * @param code
     * @return 产品ID列表
     */
    public static List<String> getProdIdByCode(String... code) {
        return getProdIdByPCode(null, code);
    }

    /**
     * 根据pkey, pcode获取产品ID
     * @param pcode
     * @param code
     * @return
     */
    public static List<String> getProdIdByPCode(String pcode, String... code) {
        List<String> prodIds = new ArrayList<>();
        List<String> codes = Arrays.asList(code);
        if (KiteListUtils.isNotEmpty(codes)) {
            if (KiteStringUtils.isNotEmpty(pcode)) {
                codes.forEach(c -> {
                    List<DcPublic> dcPublicList = DcPublicCache.getByPcode(STYPE_PROD, c, pcode);
                    if (Objects.nonNull(dcPublicList)) {
                        dcPublicList.forEach(dcPublic -> {
                            Optional.ofNullable(dcPublic.getCodea()).ifPresent(prodIds::add);
                        });
                    }
                });
            } else {
                codes.forEach(c -> {
                    List<DcPublic> dcPublicList = DcPublicCache.getByPkey(STYPE_PROD, c);
                    if (Objects.nonNull(dcPublicList)) {
                        dcPublicList.forEach(dcPublic -> {
                            Optional.ofNullable(dcPublic.getCodea()).ifPresent(prodIds::add);
                        });
                    }
                });
            }
        }
        return prodIds;
    }

    /**
     * 获取双线所有的产品ID
     * @return
     */
    public static String[] getDoubleLineProdIds() {
        List<String> prodIds = getProdIdByCode(MV_CODE, YTW_CODE, SDH_CODE, GXCZ_CODE, DIA_CODE);
        return prodIds.toArray(new String[prodIds.size()]);
    }

    /**
     * 根据code：MV, GX, SDH, YTW, DIA 获取分类ID
     * @param code
     * @return
     */
    public static String[] getProdIdByCodeForArr(String... code) {
        List<String> cateIds = getCateIdByCode(code);
        return cateIds.toArray(new String[cateIds.size()]);
    }

    /**
     * 根据code：MV, GX, DIA 获取分类ID
     * @param code
     * @return
     */
    public static String getSingleProdId(String code) {
        return DcPublicCache.getCodea(STYPE_PROD, code);
    }

    /**
     * 融合获取主成员产品ID，物联网获取产品ID
     * @param code
     * @return
     */
    public static String getMainMemberProdId(String code) {
        return DcPublicCache.getCodea(STYPE_WLW_PROD, code);
    }

    public static String[] getMainMemberProdIdForArr(String... code) {
        List<String> prodIds = new ArrayList<>();
        List<String> codes = Arrays.asList(code);
        if (KiteListUtils.isNotEmpty(codes)) {
            codes.forEach(c -> {
                Optional.ofNullable(DcPublicCache.getCodea(STYPE_WLW_PROD, c)).ifPresent(prodIds::add);
            });
        }
        return prodIds.toArray(new String[prodIds.size()]);
    }

    public static String getSubMemberProdId(String code) {
        return DcPublicCache.getCodeb(STYPE_WLW_PROD, code);
    }
}
